import BaseModel from './baseModel'
import { get } from '../ajax/axios'
import { Api } from '../ajax/api'
import TimeStamp from 'time-stamp'
import { ImageMfit } from '../utils/filters'

// 首页轮播图对象
class StudyModel extends BaseModel {

  title = ''
  pic = ''
  date = ''
  describe = ''
  content = ''

  get dateStr() {
    return this.date ? TimeStamp('YYYY/MM/DD', new Date(this.date)) : ''
  }

  get pcMeIconUrl() {
    return ImageMfit(this.pic, 150, 150)
  }

  get pcListIconUrl() {
    return ImageMfit(this.pic, 100, 100)
  }

  static async getMeModels() {
    const json = await get(Api.study.me) as any
    return this.modelsWithArr(json)
  }

  static async getModels(data: {}) {
    const json = await get(Api.study.list, data) as any
    return {
      list: this.modelsWithArr(json.list),
      total: json.total
    }
  }

  static getTypes() {
    return get(Api.study.types)
  }

  static async getDetail(id: string) {
    const json = await get(`${Api.study.detail}${id}`) as any
    const model = new this()
    model.setDataWithJson(json)
    return model
  }
}

export default StudyModel
